package com.jnks.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jnks.mapper.DroneTMapper;
import com.jnks.pojo.domain.vo.DroneRedisWzMqttVo;
import com.jnks.pojo.domain.vo.DroneSelectRequestVo;
import com.jnks.pojo.domain.vo.KV;
import com.jnks.pojo.entity.DroneTDO;
import com.jnks.service.DailyMonitorService;
import com.jnks.utils.Condition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 日常监控 服务实现类
 * </p>
 *
 * @author Ryo
 * @since 2023-04-09
 */
@Service
public class DailyMonitorServiceImpl implements DailyMonitorService {

    @Autowired
    private DroneTMapper droneTMapper;

    @Autowired
    private DroneDataServiceImpl droneDataService;

    @Override
    public List<KV> getStatistics() {
        List<DroneRedisWzMqttVo> filteredList = droneDataService.hisDroneDirectDaily().stream()
                .filter(vo -> vo.getType() != 7) // 过滤条件
                .collect(Collectors.toList());
        Integer size = filteredList.size();
        Integer today = droneTMapper.selectCountToday();
        Integer todayAmount = today + size;

        //今日侦测
        KV kv1 = new KV("todayAmount", todayAmount);
        KV kv2 = new KV();
        //历史侦测
        kv2.setKey("totalAmount");
        Integer totalAmountBeforeToday = droneTMapper.selectCountTotal();
        kv2.setValue(totalAmountBeforeToday);
        return Arrays.asList(kv1, kv2);
    }

    @Override
    public IPage<DroneTDO> hisDroneList(DroneSelectRequestVo vo) {
        IPage<DroneTDO> page = Condition.getPage(vo);

        IPage<DroneTDO> droneTDOIPage = droneTMapper.selectDroneList(page,vo);
        return droneTDOIPage;
    }

}
